package com.zking.web;

import com.zking.utils.StringUtils;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;


	public static final String PREFIX = "/WEB-INF/admin/";//后台页面的前缀
	public static final String SUFFIX = ".jsp";//后台页面的后缀

	/**
	 * 转发页面的方法(后台)
	 * @param path 需要转发的jsp页面名称
	 */
	public void dispatcher(String path, HttpServletRequest request,
						   HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher(PREFIX+path+SUFFIX).forward(request, response);
	}

	/**
	 * 获取前端的m方法值，默认是index
	 */
	public String getM(HttpServletRequest request){
		//获取前端的访问方法
		String m = request.getParameter("m");
		//如果m是空，就默认是首页
		return StringUtils.isBlank(m) ? "index" : m;
	}

}